package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.Salestate;
import com.ruoyi.house_sale.service.ISalestateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售状态Controller
 * 
 * @author ruoyi
 * @date 2022-03-30
 */
@RestController
@RequestMapping("/house_sale/salestate")
public class SalestateController extends BaseController
{
    @Autowired
    private ISalestateService salestateService;

    /**
     * 查询销售状态列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:salestate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Salestate salestate)
    {
        startPage();
        List<Salestate> list = salestateService.selectSalestateList(salestate);
        return getDataTable(list);
    }

    /**
     * 导出销售状态列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:salestate:export')")
    @Log(title = "销售状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Salestate salestate)
    {
        List<Salestate> list = salestateService.selectSalestateList(salestate);
        ExcelUtil<Salestate> util = new ExcelUtil<Salestate>(Salestate.class);
        util.exportExcel(response, list, "销售状态数据");
    }

    /**
     * 获取销售状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:salestate:query')")
    @GetMapping(value = "/{saleid}")
    public AjaxResult getInfo(@PathVariable("saleid") Long saleid)
    {
        return AjaxResult.success(salestateService.selectSalestateBySaleid(saleid));
    }

    /**
     * 新增销售状态
     */
    @PreAuthorize("@ss.hasPermi('house_sale:salestate:add')")
    @Log(title = "销售状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Salestate salestate)
    {
        return toAjax(salestateService.insertSalestate(salestate));
    }

    /**
     * 修改销售状态
     */
    @PreAuthorize("@ss.hasPermi('house_sale:salestate:edit')")
    @Log(title = "销售状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Salestate salestate)
    {
        return toAjax(salestateService.updateSalestate(salestate));
    }

    /**
     * 删除销售状态
     */
    @PreAuthorize("@ss.hasPermi('house_sale:salestate:remove')")
    @Log(title = "销售状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleids}")
    public AjaxResult remove(@PathVariable Long[] saleids)
    {
        return toAjax(salestateService.deleteSalestateBySaleids(saleids));
    }
}
